package com.springtest.Controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;

import com.hnair.OdsConsumer;
import com.hnair.QueryMbrInfo;

import org.jasig.cas.client.authentication.AttributePrincipal;
import org.jasig.cas.client.util.AbstractCasFilter;
import org.jasig.cas.client.validation.Assertion;

import java.util.Map;

@Controller
@RequestMapping("view/ssologin/*")
public class ssologin {
	private static Logger logger = Logger.getLogger(login.class);  
	
	@RequestMapping("login.do")
	public String ssoLogin(HttpServletRequest request,HttpServletResponse response) throws IOException
	{
		
//		HttpServletRequest httpRequest = (HttpServletRequest)request;
//		HttpServletResponse httpResponse = (HttpServletResponse)response;
//		String path = httpRequest.getServletPath();
		
		
		AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal(); 
		
		HttpSession session = request.getSession();
		if(principal == null){
			session.setAttribute("", "");
		}else{
			session.setAttribute("", principal);
		}
		
////		AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal(); 
////		
////		Map attributes = principal.getAttributes(); 
////		String custno=(String)attributes.get("custno"); //客户号
////		String custname=(String)attributes.get("custname"); //客户姓名
////		String employid =(String)attributes.get("employid"); //员工id
////		String employflag =(String)attributes.get("employflag"); //是否内部员工
////		String custtype =(String)attributes.get("custtype"); //客户类型
////		String alipayid =(String)attributes.get("alipayid");//支付宝账号
////		String qqid =(String)attributes.get("qqid");//qq账号
////		String mobileno =(String)attributes.get("mobileno"); //手机号
////		String email =(String)attributes.get("email"); //邮箱
////		String grpid =(String)attributes.get("grpid"); //金鹏卡号
////		
////		HttpSession session = request.getSession();
////		session.setAttribute("custno", custno);
////		session.setAttribute("custname", custname);
////		session.setAttribute("employid", employid);
////		session.setAttribute("employflag", employflag);
////		session.setAttribute("custtype", custtype);
////		session.setAttribute("alipayid", alipayid);
////		session.setAttribute("qqid", qqid);
////		session.setAttribute("mobileno", mobileno);
////		session.setAttribute("email", email);
////		session.setAttribute("grpid", grpid);
////
////		
////		//String StrUrl = request.getScheme() + ;
////		//logger.debug("sso:" +StrUrl);
//////		logger.debug(request.getScheme());
//////		logger.debug(request.getServerName());
//////		logger.debug(request.getServerPort());
//////		logger.debug(request.getContextPath());
//////		logger.debug(request.getServletPath());
//		logger.debug(principal);
		response.sendRedirect("/SpringTest/index.jsp");
		return null;
	}
	
	
}
